<template>
  <div class="nav-bar">
    <div class="bar-box">
      <div class="logo">
        <img src="~assets/images/bg-logo.jpg">
      </div>
      <div class="tab">
        <div
          v-for="(item, index) in tabs"
          :key="index"
          class="tab-item"
          :class="{active: current === item.title}"
          @click="select(item, index)"
        >
          <span>{{ item.title }}</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data () {
    return {
      tabs: [
        {
          title: '首页',
          path: '/'
        },
        {
          title: '我的书架',
          path: '/bookshelf'
        },
        {
          title: '我的',
          path: '/me'
        }
      ],
      current: '首页'
    }
  },
  mounted () {
    this.changeTab()
  },
  methods: {
    select (item, index) {
      this.current = index
      this.$emit('select', item)
    },
    changeTab () {
      const path = '/' + this.$route.path.split('/')[1]
      const filterCurrent = this.tabs.filter(ele => ele.path === path)
      this.current = filterCurrent[0].title
    }
  }
}
</script>

<style lang="css" scoped>
.nav-bar {
  padding: 0 20px;
  border-bottom: 1px solid rgba(143, 145, 143, 0.1);
}
.nav-bar .bar-box {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 1200px;
  margin: 0 auto;
}
.nav-bar .logo {
  width: 60px;
  height: 60px;
  margin: 10px 0;
}
.nav-bar .logo img {
  width: 100%;
}
.nav-bar .tab {
  display: flex;
  align-content: space-between;
  align-items: center;
}
.nav-bar .tab-item {
  display: flex;
  align-content: center;
  align-items: center;
  height: 60px;
  margin: 0 15px;
  font-size: 14px;
  cursor: pointer;
}
.nav-bar .tab-item.active {
  border-bottom: 2px solid #f26552;
  color: #f26552;
}
</style>
